﻿@page
@inherits Acesoft.Web.UI.RazorPages.WebPage
@{
    Layout = "_shared/edit";
    ViewData["Title"] = "编辑";

    Ace.View().Id("view").Ajax(ds => ds.DataSource("sys.field").Form(new
    {
        table = App.GetQuery("tableid", ""),
        field = "",
        name = "",
        type = 0,
        length = 20,
        isnull = 1,
        unique = 0,
        created = 0,
        @ref = "",
        orderno = 100,
        system = 0,
        remark = ""
    }).HttpSave()).Content(
        @<div class="container-fluid">
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 字段：</div>
                <div class="col-xs-6">@Ace.TextBox().Name("field").Width("100%").Required().ValidType("length[2,20]")</div>
                <div class="col-xs-4"><div class="text-warning">长度2-20的字母或下划线！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 名称：</div>
                <div class="col-xs-6">@Ace.TextBox().Name("name").Width("100%").Required().ValidType("length[2,20]")</div>
                <div class="col-xs-4"><div class="text-warning"></div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 类型：</div>
                <div class="col-xs-6">
                    @(Ace.ComboBox().Name("type").Events(e => e.OnChange("onTypeChange"))
                        .Width("100%").Required().Ajax(ds => ds.Dict("FIELDTYPE").HttpGet()))
                </div>
                <div class="col-xs-4"><div class="text-warning">请参照数据库类型选择！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 字典：</div>
                <div class="col-xs-6">
                   @(Ace.ComboTree().Id("dict").Events(e => e.OnChange("onRefChange")).PanelHeight(160)
                        .Disabled().Ajax(ds => ds.DataSource("sys.dict_tree").HttpGet()).Width("100%"))
                </div>
                <div class="col-xs-4"><div class="text-warning">选择字典类！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 引用：</div>
                <div class="col-xs-6">@Ace.TextBox().Name("ref").Width("100%").Required().Disabled()</div>
                <div class="col-xs-4"><div class="text-warning">填写引用表名！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 长度：</div>
                <div class="col-xs-6">@Ace.NumberBox().Name("length").Width("100%").Required()</div>
                <div class="col-xs-4"><div class="text-warning">为数字时包含小数点和2位小数</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r">设置：</div>
                <div class="col-xs-6">
                    @Ace.CheckBox().Name("isnull").Text("可空　")
                    @Ace.CheckBox().Name("unique").Text("唯一　")
                    @Ace.CheckBox().Name("system").Text("系统")
                </div>
                <div class="col-xs-4"><div class="text-warning">系统属性不能删除！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r"><span class="cr-red">*</span> 排序号：</div>
                <div class="col-xs-6">@Ace.NumberSpinner().Name("orderno").Increment(10).Width("100%").Required()</div>
                <div class="col-xs-4"><div class="text-warning">设置时建议按10，20递增！</div></div>
            </div>
            <div class="row">
                <div class="col-xs-2 text-r">备注：</div>
                <div class="col-xs-6">@Ace.TextBox().Name("remark").Width("100%")</div>
                <div class="col-xs-4"></div>
            </div>
        </div>
    ).Render();
}
@section startup{
<script>
    var loading = true;
    var len = [20, 20, 16, 1, 4, 8, 18, 128, 20, 4, 8, 8, 8, 20];
    var dis = [0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0];
    function onSubmit(cb) {
        $('#ref').textbox('enable');
        $('#length').numberbox('enable');
        AX.formSubmit('#view', cb);
    }
    function onRefChange(nv, ov) {
        $('#ref').textbox('setValue', nv);
    }
    function onTypeChange() {
        var index = $('#type').combobox('getIndex');
        var lenObj = { required: dis[index] == 0 };
        if (!loading) {
            $('#ref').textbox('setValue', '');
            lenObj.value = len[index];
        }
        $('#length').numberbox(lenObj);
        if (dis[index]) $('#length').numberbox('disable');
        else $('#length').numberbox('enable');

        if (index == 8 || index == 9) {
            $('#dict').combotree({ required: true }).combotree('enable');
            $('#ref').textbox('disableValidation').textbox('disable');
        }
        else if (index > 10) {
            $('#dict').combotree({ required: false }).combotree('disable');
            $('#ref').textbox('enable').textbox('enableValidation');
        }
        else {
            $('#dict').combotree({ required: false }).combotree('disable');
            $('#ref').textbox('disableValidation').textbox('disable');
        }
    }
    $(function () {
        setTimeout(function () {
            onTypeChange();
            $('#dict').combotree('setValue', $('#ref').textbox('getValue'));
            loading = false;
        }, 100);
    });
</script>
}